`
https://leetcode.cn/problems/integer-break/
`

/**
 * @param {number} n
 * @return {number}
 */
var integerBreak = function (n) {
  const memo = new Array(n + 1).fill(-1)

  // 拆分 n 获得的最大乘积为 dp(n)
  function dp(n) {
    if (n === 0 || n === 1) {
      return n
    }

    if (memo[n] !== -1) {
      return memo[n]
    }

    let res = -Infinity
    for (let i = 1; i <= n; i++) {
      //   integerBreak(4)
      // = max(1 * 3, 1 * integerBreak(3), 2 * 2, 2 * integerBreak(2))
      res = Math.max(res, i * dp(n - i), i * (n - i))
    }

    memo[n] = res
    return res
  }

  return dp(n)
};